package com.example.legodigitalsonoro1;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.bluetooth.BluetoothAdapter;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

/**
 * this class manage the initialization game phase
 * @author chiara
 *
 */
public class MainActivity extends Activity {
	
	public static final String MODE="mode";
	public static final String singlePlayer="SinglePlayer";
	public static final String multiPlayerServer = "MultiPlayerServer";
	public static final String multiPlayerClient = "MultiPlayerClient";
	
	private Intent intent;
	private int REQUEST_ENABLE_BT;
	

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        
    }
    
    @Override
    protected void onStart() {
    	super.onStart();
    }
    
    @Override
    protected void onStop() {
    	super.onStop();
    }
    
    @Override
    protected void onDestroy() {
    	super.onDestroy();
    }
    
    /**
     * method called when the user selects the settings button
     * @param v
     */
    public void changeSettings(View v){
    	 getFragmentManager().beginTransaction()
         .replace(android.R.id.content, new SettingsFragment())
         .addToBackStack("settings")
         .commit();
    }
    
    /**
     * method called when the user selects the single match button
     * @param b
     */
    public void startSingleMatch(View b){
    	intent=new Intent(this, MatchActivity.class);
    	intent.putExtra(MODE, singlePlayer);
    	startActivity(intent);
    }
    
    /**
     * method called when the player selects the multi player button
     * @param b
     */
	public void startMultiplePlayersMatch(View b) {

		BluetoothAdapter mBluetoothAdapter = BluetoothAdapter
				.getDefaultAdapter();
		if (mBluetoothAdapter == null) {
			
			AlertDialog.Builder builder= new Builder(this);
			builder.setTitle("Warning");
			builder.setMessage("Sorry, your device doesn't support Bluetooth connection.");
			builder.setCancelable(true);
			builder.setNeutralButton(R.string.ok, new OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					dialog.cancel();
				}
			});
			builder.create().show();
			
		} else {
			
			if (!mBluetoothAdapter.isEnabled()) {
				Intent enableBtIntent = new Intent(
						BluetoothAdapter.ACTION_REQUEST_ENABLE);
				startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
			}
			
			Intent intent=new Intent(this, ConnectionSetupActivity.class);
			startActivity(intent);
		}
	}
	

}
